Application Configuration and Integration Tests
Let’s learn how to configure the application and perform integration tests.
We'll cover the following
Application configuration#
Docker Compose, the testing framework, and the application itself are configured through a single JSON file that we need to update with the actual values we want to use for MongoDB.
Since the standard port for MongoDB is 27017, we choose 27018 for the tests in our example. In a real scenario, we may have multiple environments and multiple setups for our testing. In that case, we may want to assign a random port to the container and use Python to extract the value and pass it to the application.
We’re also using the same APPLICATION_DB variable for the name of the PostgreSQL and MongoDB databases. Again, this is a simple example, and our practice may vary in more complex scenarios.
Integration tests#
Our integration tests mirror the ones we wrote for PostgreSQL, since we’re covering the same use case. If we were using multiple databases in the same system, we would probably want to serve different use cases, which means that this step in a real case would be much more complicated than in our example. However, it’s also completely reasonable for us to want to provide support for multiple databases that our client may want to plug into the system. In that case, we’ll do exactly what we did here, namely copy and adjust the same test battery.
In the code above, we add a test called test_repository_list_with_price_as_string that checks what happens when the price in the filter is expressed as a string. When we experiment with the MongoDB shell, we find that the query doesn’t work, so we include the test to ensure that the implementation doesn’t forget to manage this condition.
Updated code#
In the code editor, we’ve updated the files with the new code.
/
Fixtures and Docker Compose
The MongoDB Repository